/**
 * @projectName study_java
 * @package Prototype
 * @className Prototype.Prototype
 */
package Prototype;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Prototype
 * @description 抽象 原型类
 * @author answer_wx
 * @date 2022/6/27 11:07
 * @version 1.0
 */
@Data
public class Prototype implements Cloneable {
    private String name;
    private int age;
    private String sex;
    private ArrayList<String> jobs;

    public Prototype(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public Prototype shallowClone() throws CloneNotSupportedException {
        return (Prototype) super.clone();
    }

    public Prototype deepClone() throws CloneNotSupportedException {
        Prototype clone = (Prototype) super.clone();
        ArrayList<String> jobs = clone.getJobs();
        clone.setJobs((ArrayList<String>) jobs.clone());
        return clone;
    }

    @Override
    public String toString() {
        return "Prototype{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                ", jobs=" + jobs +
                '}';
    }
}